<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>设置</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>
    <div class="list-text-r mt20">
        <ul>
            <li onclick="fixPwd();">
                登录密码
                <i class="fa fa-angle-right"></i>
            </li>
            <li onclick="fixPayPwd();">
                支付密码
                <i class="fa fa-angle-right"></i>
            </li>
            <li onclick="clearCache();">
                清除缓存
                <p id="cache">0.00M</p>
                <i class="fa fa-angle-right"></i>
            </li>
            <li onclick="setupNotice();">
                通知设置
                <i class="fa fa-angle-right"></i>
            </li>
            <li onclick="address();">
                收货地址管理
                <i class="fa fa-angle-right"></i>
            </li>
<!--             <li onclick="aboutUs();">
                关于我们
                <i class="fa fa-angle-right"></i>
            </li> -->
            <li  onclick="logout();">
                退出登录
                <i class="fa fa-angle-right"></i>
            </li>
        </ul>
    </div>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){
        cacheValue();
    }

    // 修改登录密码
    function fixPwd(){
        api.openWin({
            name: 'fix_pwd',
            url: './fix_pwd.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    // 修改支付密码
    function fixPayPwd(){
        api.openWin({
            name: 'fix_pay_pwd',
            url: './fix_pay_pwd.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    // 缓存数值
    function cacheValue(){
        // 异步返回结果：
        api.getCacheSize(function(ret) {
            var size = ret.size;
            size = (size/1048576).toFixed(2);
            $('#cache').html(size+'M');
        });
    }

    // 通知设置
    function setupNotice(){
        api.openWin({
            name: 'setup_notice',
            url: './setup_notice.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    // 退出登录
    function logout(){
        api.confirm({
            title: '提示',
            msg: '是否退出?',
            buttons: ['确定', '取消']
        }, function(ret, err){
            if( ret ){
                if (ret.buttonIndex == 1) {
                    $api.setStorage('token', null);
                    var setSele = 'gotoIndex();';
                    api.execScript({
                        name: 'root',
                        script: setSele,
                    });
                    api.closeWin();
                    return false;
                }
            }else{
             return false;
         }
     });


    }

    // 清除缓存
    function clearCache(){
        api.confirm({
            title: '提示',
            msg: '是否清除缓存?',
            buttons: ['确定', '取消']
        }, function(ret, err){
            if( ret ){
             if (ret.buttonIndex == 1) {
                api.clearCache(function() {
                    api.toast({
                        msg: '清除完成',
                        duration: 2000,
                        location: 'bottom'
                    });
                    cacheValue();
                });
            }
        }else{
                // alert( JSON.stringify( err ) );
            }
        });
    }

    // 收货地址
    function address() {
      api.openWin({
        name: 'address',
        url: './address.html',
      });
    }

    // 关于我们
    function aboutUs(){
        // 跳转网页
        api.openWin({
            name: 'web_view',
            url: './web_view.html',
            pageParam: {
                url: 'http://yipinyizhuan.com/api/wap/html?key=about',
                title: '关于我们',
            }
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>